package se392.ateam2006.resourcemgmt.room;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * Entity class to define the attributes and operations of a Room (i.e. its capacity and location, etc)
 * This information can then be persisted into a database
 * @author Ateam (Matthew Bennett, Claire Melton, Shingai Manyiwa, John Adderley)
 * @version 25/03/07
 */
@Entity
public class RoomEntity implements Serializable {
    
    @Id
    private String roomID;
    private int capacity;
    private String location;
    private String owner;
    
    /**
     * Default constructor required as this is an Entity class
     */
    public RoomEntity() {}
    
    /**
     * Creates a new instance of RoomEntity
     * @param roomID - String, the ID of the room
     * @param cap - int, the capactity of the room (number of people it can accomodate)
     * @param location - String, the location of the room
     * @param owner - String, the owner of the room
     */
    public RoomEntity(String roomID, int cap, String location, String owner) {
        setRoomID(roomID);
        setCapacity(cap);
        setLocation(location);
        setOwner(owner);
    }
    
    /**
     * Override the equals method...
     * @param obj - Object, the object to compare to
     * @return boolean - are the objects equal?
     */
    public boolean equals(Object obj) {
        
        if(obj instanceof RoomEntity) {
            
            RoomEntity otherItem = (RoomEntity)(obj);
            
            if(this.getRoomID().equals(otherItem.getRoomID())&&
                    this.getCapacity()==(otherItem.getCapacity())&&
                    this.getLocation().equals(otherItem.getLocation())&&
                    this.getOwner().equals(otherItem.getOwner())) {
                
                return true;
            }else{
                return false;
            }
        }
        
        return false;
    }
    
    /**
     * Get the ID of the room
     * @return String - the ID of the room
     */
    public String getRoomID() {
        return roomID;
    }
    
    /**
     * Set the ID of the room
     * @param roomID - String, the new ID of the room
     */
    public void setRoomID(String roomID) {
        this.roomID = roomID;
    }
    
    /**
     * Get the capacity of the room
     * @return int - the capacity of the room
     */
    public int getCapacity() {
        return capacity;
    }
    
    /**
     * Set the capacity of the room
     * @param cap - int, the new capacity of the room
     */
    public void setCapacity(int cap) {
        this.capacity = cap;
    }
    
    /**
     * Get the location of the room
     * @return String - the location of the room
     */
    public String getLocation() {
        return location;
    }
    
    /**
     * Set the location of the room
     * @param location - String, the new location of the room
     */
    public void setLocation(String location) {
        this.location = location;
    }
    
    /**
     * Get the owner of the room
     * @return String - the owner of the room
     */
    public String getOwner() {
        return owner;
    }
    
    /**
     * Set the owner of the room
     * @param owner - String, the new owner of the room
     */
    public void setOwner(String owner) {
        this.owner = owner;
    }
    
    /**
     * Override the toString method
     * @return String - a string representation of the room
     */
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("RoomID: " + this.roomID);
        buffer.append("\nCapacity: " + String.valueOf(this.capacity));
        buffer.append("\nLocation: " + this.location);
        if(null == this.owner)
            buffer.append("\nOwner: <not set>");
        else
            buffer.append("\nOwner: " + this.owner);
        
        return buffer.toString();
    }
}

